# OS Environment
ARCH := $(shell uname -m)
CCACHE := $(shell which ccache 2>/dev/null)
CXX = ${CCACHE} g++
OS = $(shell uname -s)

# Flags
DEBUG_FLAGS = -g -pg
DEF_FLAGS = -D${ARCH} -pthread
OPT_FLAGS = -O3
WARN_FLAGS = -Wall

# Project
LIBDIR = build/lib
SRCDIR = src/cpp

LIBNAME = libprovident.a
HEADERS = expiry/ExpiryCalculator.hpp \
          models/analytical/BlackScholes.hpp \
          models/binomial/BinomialTree.hpp \
          options/VanillaOption.hpp \
          yieldcurve/YieldCurve.hpp
INCLUDES = -Isrc/cpp/expiry -Isrc/cpp/options -Isrc/cpp/yieldcurve
OBJDIR = build/obj
OBJS = expiry/ExpiryCalculator.o \
       models/analytical/BlackScholes.o \
       options/VanillaOption.o \
       yieldcurve/YieldCurve.o

SRCDIR_HEADERS = ${addprefix ${SRCDIR}/, ${HEADERS}}
OBJDIROBJS = ${addprefix ${OBJDIR}/, ${OBJS}}

all: install

clean: 
	@echo -e "\033[7m[Cleaning...]\033[0m"
	rm -rf ${OBJDIROBJS} ${LIBNAME} ${LIBDIR}/${LIBNAME} include/*

install: lib
	@echo -e "\033[7m[Installing...]\033[0m"
	cp ${SRCDIR_HEADERS} include/
	#${CXX} src/cpp/tools/CLICalculator.cpp -o build/cli-calculator ${DEBUG_FLAGS} ${DEF_FLAGS} ${OPT_FLAGS} ${WARN_FLAGS} -Iinclude -L${LIBDIR} -lprovident -lpromote++ -pthread -lm

lib: compile_echo ${OBJDIROBJS}
	@echo -e "\033[7m[Creating library...]\033[0m"
	ar rcs ${LIBDIR}/${LIBNAME} ${OBJDIROBJS}

compile_echo:
	@echo -e "\033[7m[Compiling...]\033[0m"

${OBJDIR}/%.o: ${SRCDIR}/%.cpp ${SRCDIR_HEADERS}
	@if [ ! -d "${dir $@}" ]; \
	then \
		mkdir -p ${dir $@}; \
	fi; \
	${CXX} ${DEBUG_FLAGS} ${DEF_FLAGS} ${OPT_FLAGS} ${WARN_FLAGS} ${INCLUDES} -c ${SRCDIR}/$*.cpp -o $@

.PHONY: all clean

